updating oE parse
parse
include datetime.e -- (default namespace is datetime) public function parse(sequence val, sequence fmt = "%Y-%m-%d %H:%M:%S", integer yylower = - 80)
Parses a datetime string according to the given format.
Parameters:
- val : string datetime value
- fmt : datetime format. Default is "%Y-%m-%d %H:%M:%S"
- yysplit : Set the maximum difference from the current year when parsing a two digit year. Defaults to -80/+20.
Returns:
A datetime, value.
Comments:
Only a subset of the format specification is currently supported:
- %d -- day of month (e.g, 01)
- %H -- hour (00..23)
- %m -- month (01..12)
- %M -- minute (00..59)
- %S -- second (00..60)
- %y -- 2-digit year (YY)
- %Y -- 4-digit year (CCYY)
More format codes will be added in future versions.
All non-format characters in the format string are ignored and are not matched against the input string.
All non-digits in the input string are ignored.
Parsing Two Digit Years:
When parsing a two digit year parse has to make a decision if a given year is in the past or future. For example, 10/18/44. Is that Oct 18, 1944 or Oct 18, 2044. A common rule has come about for this purpose and that is the -80/+20 rule. Based on research it was found that more historical events are recorded than future events, thus it favors history rather than future. Some other applications may require a different rule, thus the yylower parameter can be supplied.
Assuming today is 12/22/2010 here is an example of the -80/+20 rule:
YY | Diff | CCYY |
---|---|---|
18 | -92/+8 | 2018 |
95 | -15/+85 | 1995 |
33 | -77/+23 | 1933 |
29 | -81/+19 | 2029 |
Another rule in use is the -50/+50 rule. Therefore, if you supply -50 to the yylower to set the lower bounds, some examples may be (given that today is 12/22/2010):
YY | Diff | CCYY |
---|---|---|
18 | -92/+8 | 2018 |
95 | -15/+85 | 1995 |
33 | -77/+23 | 2033 |
29 | -81/+19 | 2029 |
Note:
- Since 4.0.1 -- 2-digit year parsing and yylower parameter.
Example 1:
include std/datetime.e datetime d = parse("05/01/2009 10:20:30", "%m/%d/%Y %H:%M:%S") ? d
Result:
{2009,5,1,10,20,30 }
Example 2:
include std/datetime.e datetime d = parse("05/01/44", "%m/%d/%y", -50) -- -50/+50 rule ? d
Result:
{2044,5,1,0,0,0}
See Also:
Not Categorized, Please Help
|